- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=ipa:ipa-stg"

- name: make the box be real
  hosts: ipa:ipa-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - base
  - rkhunter
  - nagios_client
  - hosts
  - fas_client
  - rsyncd
  - sudo
  - { role: openvpn/client,
      when: env != "staging" }
  - mod_wsgi

  tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"
  - import_tasks: "{{ tasks_path }}/2fa_client.yml"
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: deploy ipa itself
  hosts: ipa:ipa-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - "{{ vars_path }}/{{ ansible_distribution }}.yml"

  roles:
  - ipa/server
  - role: keytab/service
    owner_user: apache
    owner_group: apache
    service: HTTP
    host: "id{{env_suffix}}.fedoraproject.org"
    notify:
    - combine IPA http keytabs

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

  tasks:
  - name: Combine IPA keytabs
    shell: printf "%b" "read_kt /etc/httpd/conf/ipa.keytab\nread_kt /etc/krb5.HTTP_id{{env_suffix}}.fedoraproject.org.keytab\nwrite_kt /etc/krb5.HTTP_id{{env_suffix}}.fedoraproject.org.keytab.combined" | ktutil
    changed_when: false
    tags:
    - krb5
    - ipa/server
  - name: Set owner and permissions on combined keytab
    file: path="/etc/krb5.HTTP_id{{env_suffix}}.fedoraproject.org.keytab.combined"
          owner=apache
          group=apache
          mode=0600
    tags:
    - krb5
    - ipa/server
  # original: /etc/httpd/conf/ipa.keytab
  #- name: Make IPA HTTP use the combined keytab
  #  lineinfile: dest=/etc/httpd/conf.d/ipa.conf
  #              regexp='GssapiCredStore keytab:'
  #              line='  GssapiCredStore keytab:/etc/krb5.HTTP_id{{env_suffix}}.fedoraproject.org.keytab.combined'
  #  tags:
  #  - krb5
  #  - ipa/server
  #  - config
  #- name: Make IPA HTTP use the id.fp.o client keytab
  #  lineinfile: dest=/etc/httpd/conf.d/ipa.conf
  #              regexp='GssapiCredStore client_keytab:'
  #              line='  GssapiCredStore client_keytab:/etc/krb5.HTTP_id{{env_suffix}}.fedoraproject.org.keytab'
  #  tags:
  #  - krb5
  #  - ipa/server
  #  - config

- name: do base role once more to revert any resolvconf changes
  hosts: ipa:ipa-stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - "{{ vars_path }}/{{ ansible_distribution }}.yml"

  roles:
  - base

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
